package com.mi.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.mi.dao.UserDao;
import com.mi.entity.User;



@Repository
public class UserDaoImpl implements UserDao{

	@Resource     /*注入template到bean工厂中*/
	private HibernateTemplate template;
	
	/*根据用户名查询当前用户信息*/
	public User LoginUser(String userName) {	
		System.out.println(userName);
		    List<User> list = (List<User>) template.find("from User where userName=?",userName);
		    try {
				User user = list.get(0);
				return user;
			} catch (Exception e) {
				return null;
	
			}
	
	}
	/*注册添加用户信息*/
	@Transactional
	public boolean  addUser(User user) {
       try {
    	   template.save(user);
    	   return true;
	} catch (Exception e) {
		   return false;
	}
			
			       	
	}

	

}
